package org.smile.report.poi;

import org.apache.poi.ss.usermodel.*;

/**
 * 导出excel单元样式
 */
public class ExcelExportCellStyles {

    public CellStyle defaultHeadStyle(Workbook workbook) {
        CellStyle style = workbook.createCellStyle();
        alignmentCenter(style);
        Font font = workbook.createFont();
        font.setFontHeightInPoints((short) 11);
        font.setBold(true);
        style.setFont(font);
        style.setFillForegroundColor(IndexedColors.CORNFLOWER_BLUE.getIndex());
        style.setFillPattern(CellStyle.SOLID_FOREGROUND);
        return style;
    }

    public CellStyle defaultDataStyle(Workbook workbook) {
        CellStyle style = workbook.createCellStyle();
        alignmentCenter(style);
        Font font = workbook.createFont();
        font.setFontHeightInPoints((short) 11);
        style.setFont(font);
        return style;
    }

    /**
     * 设置中间对齐
     * @param style
     */
    protected void alignmentCenter(CellStyle style){
        style.setAlignment(CellStyle.ALIGN_CENTER);
        style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    }
}
